#include "index_buffer.h"

#include "renderer.h"

IndexBuffer::IndexBuffer(const uint32_t* data, uint32_t count)
    : count_(count)
{
    static_assert(sizeof(uint32_t) == sizeof(GLuint), "use uint32_t as GLuint");

    GLCALL(glGenBuffers(1, &rendererID_));
    GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rendererID_));
    GLCALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), data, GL_STATIC_DRAW));
}

IndexBuffer::~IndexBuffer()
{
    GLCALL(glDeleteBuffers(1, &rendererID_));
}

void IndexBuffer::Bind() const
{
    GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rendererID_));
}

void IndexBuffer::Unbind() const
{
    GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
}
